export default {
    // 命名空间锁
    namespaced: true,
    state: {
        token: ""
    },
    getters: {},
    mutations: {
        setToken(state, payload) {
            console.log(payload,10);
            state.token = payload.token
        }
    },
    actions: {
        // 获取token
        async getToken({commit}) {
            //获取用户信息
            const [err, { encryptedData, rawData, iv, signature }] =
                await uni.getUserProfile({
                    desc: "用于提供更好的服务",
                });
            // console.log(encryptedData, rawData, iv, signature,126);

            //获取 code
            const [err2, { code }] = await uni.login();
            // console.log(code,130);

            //获取token   //后端接口问题 第一次会拿不到 点两次就行了
            const { token } = await uni.$u.post("/users/wxlogin", {
                encryptedData,
                rawData,
                iv,
                signature,
                code,
            });
            // console.log(state, 33);
            commit("setToken", { token })
        }
    }
}